/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.edu.unmsm.fisi.ceiecbt.app.servlets;

import java.io.*;
import java.net.*;

import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.*;
import javax.servlet.http.*;
import net.sf.jasperreports.engine.*;

import pe.edu.unmsm.fisi.ceiecbt.app.clases.ReporteNatural;
import pe.edu.unmsm.fisi.ceiecbt.app.utiles.Reporter;

/**
 *
 * @author Davis
 */
public class Reporte extends HttpServlet {
   
  

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
    * Handles the HTTP <code>GET</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        try {
            //processRequest(request, response);
            ArrayList<ReporteNatural> prueba = new ArrayList<ReporteNatural>();
           // for(int i=0;i<2;i++){
                ReporteNatural reporteBean = new ReporteNatural();
                //System.out.println("ruta : "+request.getSession().getServletContext().getContextPath());
                //System.out.println("ruta1 : "+request.getSession().getServletContext().getRealPath("/reporte/ContratoPatrocinio.jasper"));
                reporteBean.setStrL_Email("dcarhuancho@hotmail.com");
                reporteBean.setStrL_NumeroDocu("123456");
                reporteBean.setStrL_Inversion("122");
                reporteBean.setStrL_Nombres("Davis");
                reporteBean.setStrL_apellidos("Carhuancho");
                reporteBean.setStrL_NumeroDocu("12345678");
                reporteBean.setStrL_PerfilPatro("ahaha");
                reporteBean.setStrL_ResponsableEmpre("aaa" );
                reporteBean.setStrL_TipoPatro("accionista");
                prueba.add(reporteBean);
            //}
            
            File f = File.createTempFile("SolicitudPatrocinio", ".pdf");
            Reporter objL_reporter = new Reporter();
            objL_reporter.exportReport(request.getSession().getServletContext().getRealPath("/reporte/ContratoPatrocinio.jasper"), null, prueba, f);
            Runtime.getRuntime().exec(new String[]{"rundll32", "url.dll,FileProtocolHandler", f.getAbsolutePath()});
          
          
            
        } catch (JRException ex) {
            Logger.getLogger(Reporte.class.getName()).log(Level.SEVERE, null, ex);
        }  
        
    } 

    /** 
    * Handles the HTTP <code>POST</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        
    }

    /** 
    * Returns a short description of the servlet.
    */
    public String getServletInfo() {
        return "Short description";
    }
    // </editor-fold>
}
